package com.problem.binarySearch;

public class BiSearch {

    public static int search(int[] array,int a){
        int length = array.length;
        int s = 0,e=length-1;
        int i  = (e-s)/2;
        while (s>e){
            if (array[i] == a) {
                return i;
            } else if (array[i] > a) {
                e = i - 1;
//                if (e < s) {
//                    return -1;
//                }
            } else {
                s = i+1;
//                if (s > e) {
//                    return -1;
//                }
            }
            i = (e + s) / 2  ;
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] array = new int[]{1,2,3,6,7,9,11};
        System.out.println(BiSearch.search(array,8));
    }
}
